HuggingFace Diffusers 0.12 : パイプライン : 意味的ガイダンス – PyTorch 2.0

您所在的位置:网站首页 huggingface accelerate HuggingFace Diffusers 0.12 : パイプライン : 意味的ガイダンス – PyTorch 2.0

HuggingFace Diffusers 0.12 : パイプライン : 意味的ガイダンス – PyTorch 2.0

#HuggingFace Diffusers 0.12 : パイプライン : 意味的ガイダンス – PyTorch 2.0| 来源: 网络整理| 查看: 265

HuggingFace Diffusers 0.12 : API : パイプライン – 意味的ガイダンス (翻訳/解説)

翻訳 : (株)クラスキャット セールスインフォメーション 作成日時 : 03/21/2023 (v0.14.0)

* 本ページは、HuggingFace Diffusers の以下のドキュメントを翻訳した上で適宜、補足説明したものです:

API : Pipelines – Semantic Guidance

* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。 * ご自由にリンクを張って頂いてかまいませんが、[email protected] までご一報いただけると嬉しいです。

 

 

HuggingFace Diffusers 0.12 : API : パイプライン – 意味的ガイダンス

拡散モデルのための意味的ガイダンスは SEGA: Instructing Diffusion using Semantic Dimensions で紹介され、画像生成に対する強力な意味的制御を提供します。テキストプロンプトへの小さな変更は通常は全く異なる出力画像という結果になります。けれども、SEGA では、画像への様々な変更は簡単に直感的に制御できて元の画像構成に忠実であり続けることが可能になります。

論文の要約は以下のようなものです :

テキスト-to-画像変換拡散モデルは、テキストだけから高い忠実度な画像を生成する驚異的な能力のために最近は多くの関心を集めています。けれども、ユーザの意図に沿ったワンショット生成の実現は殆ど不可能で、入力プロンプトへの小さな変更は非常に異なる画像になることも多いです。このためユーザは意味的制御が殆どできないままです。私たちは、ユーザに制御させるため、意味的方向に沿ってそれを柔軟に誘導するために拡散過程と相互作用する方法を示します。この意味的ガイダンス (SEGA) は微妙で広範囲な編集、構成とスタイルの変更、そして全体的な芸術的構想の最適化を可能にします。私たちは様々なタスク上で SEGA の有効性を実演し、そしてその多様性と柔軟性のエビデンスを提供します。

  概要

パイプライン – pipeline_semantic_stable_diffusion.py タスク – テキスト-to-画像生成 – Colab

Tips

意味的ガイダンス・パイプラインは任意の Stable Diffusion チェック・ポイントとともに使用できます。

 

意味的ガイダンスの実行

SemanticStableDiffusionPipeline のインターフェイスは画像生成に影響を与える幾つかの追加のパラメータを提供しています。典型的な使用方法は以下のようなものです :

import torch from diffusers import SemanticStableDiffusionPipeline pipe = SemanticStableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) pipe = pipe.to("cuda") out = pipe( prompt="a photo of the face of a woman", num_images_per_prompt=1, guidance_scale=7, editing_prompt=[ "smiling, smile", # Concepts to apply "glasses, wearing glasses", "curls, wavy hair, curly hair", "beard, full beard, mustache", ], reverse_editing_direction=[False, False, False, False], # Direction of guidance i.e. increase all concepts edit_warmup_steps=[10, 10, 10, 10], # Warmup period for each concept edit_guidance_scale=[4, 5, 5, 5.4], # Guidance scale for each concept edit_threshold=[ 0.99, 0.975, 0.925, 0.96, ], # Threshold for each concept. Threshold equals the percentile of the latent space that will be discarded. I.e. threshold=0.99 uses 1% of the latent dimensions edit_momentum_scale=0.3, # Momentum scale that will be added to the latent guidance edit_mom_beta=0.6, # Momentum beta edit_weights=[1, 1, 1, 1, 1], # Weights of the individual concepts against each other )

For more examples check the colab notebook.

 

StableDiffusionSafePipelineOutput @dataclass class SemanticStableDiffusionPipelineOutput(BaseOutput): images: Union[List[PIL.Image.Image], np.ndarray] nsfw_content_detected: Optional[List[bool]]

パラメータ

images (List[PIL.Image.Image] or np.ndarray) — 長さ batch_size のノイズ除去された PIL 画像のリスト、または shape (batch_size, height, width, num_channels) の numpy 配列。PIL 画像や numpy 配列は拡散パイプラインのノイズ除去された画像を表しています。 nsfw_content_detected (List[bool]) — 対応する生成された画像が “not-safe-for-work” (nsfw) コンテンツを表している可能性が高いかを示すフラグのリスト、あるいは安全性チェックが実行されなかった場合は None。

Stable Diffusion パイプラインの出力クラス。

 

SemanticStableDiffusionPipeline class SemanticStableDiffusionPipeline(DiffusionPipeline): def __init__( self, vae: AutoencoderKL, text_encoder: CLIPTextModel, tokenizer: CLIPTokenizer, unet: UNet2DConditionModel, scheduler: KarrasDiffusionSchedulers, safety_checker: StableDiffusionSafetyChecker, feature_extractor: CLIPFeatureExtractor, requires_safety_checker: bool = True, ):

パラメータ

vae (AutoencoderKL) — 変分オートエンコーダ (VAE) モデル, 画像を潜在的表現に / からエンコード& デコードします。 text_encoder (CLIPTextModel) — 凍結されたテキストエンコーダ。Stable Diffusion は CLIP のテキスト部を使用します、特に clip-vit-large-patch14 バリアント。 tokenizer (CLIPTokenizer) — クラス CLIPTokenizer のトークナイザー。 unet (UNet2DConditionModel) — エンコードされた画像潜在的 (表現) をノイズ除去する条件付き U-Net アーキテクチャ。 scheduler (SchedulerMixin) — エンコードされた画像潜在的表現をノイズ除去するために unet と組み合わせて使用されるスケジューラ。DDIMScheduler, LMSDiscreteScheduler, or PNDMScheduler のいずれかが可能です。 safety_checker (Q16SafetyChecker) — 生成画像が不快や有害であると考えられるかを推定する分類モジュール。詳細は モデルカード を参照してください。 feature_extractor (CLIPFeatureExtractor) — safety_checker のために入力として使用される、生成画像からの特徴量を抽出するモデル。

潜在的表現編集によるテキスト-to-画像生成のためのパイプライン。

このモデルは DiffusionPipeline を継承しています。(ダウンロードやセーブ, 特定のデバイス上の実行等のような) すべてのパイプラインに対してライブラリが実装する汎用メソッドについてはスーパークラスのドキュメントを確認してください。

This model builds on the implementation of [‘StableDiffusionPipeline’]

 

以上



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3